﻿package mortal.game.view.guildNew.WareHourse
{
    import Message.Game.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GuildNewDonateItemPanel extends SmallWindow
    {
        private var _item:BaseItem;
        private var _itemName:GTextFiled;
        private var _numInput:GNumericStepper;
        private var _btnYes:GButton;
        private var _btnNo:GButton;
        private var _data:ItemData;
        private var _uiCreateCom:Boolean = false;
        private static var _instance:GuildNewDonateItemPanel;

        public function GuildNewDonateItemPanel(param1:ILayer = null)
        {
            setSize(245, 150);
            super(param1);
            title = "" + Language.getString(71623);
            layer = LayerManager.topLayer;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._item = UIFactory.getUICompoment(BaseItem, 25, 48, this);
            this._item.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 3);
            this._itemName = UIFactory.textField("", 70, 48, 100, 22, this);
            UIFactory.textField("" + Language.getString(71624), 70, 68, 100, 22, this);
            this._numInput = UIFactory.gNumericStepper(128, 66, 49, 20, this, 999, 1, "NumericStepper");
            this._numInput.configEventListener(Event.CHANGE, this.onUpdateNumInput);
            this._btnYes = UIFactory.gButton("" + Language.getString(71625), 46, 110, 65, 22, this);
            this._btnNo = UIFactory.gButton("" + Language.getString(71626), 135, 110, 65, 22, this);
            this._uiCreateCom = true;
            this.configEventListener(MouseEvent.CLICK, this.onMouseClick);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._data = null;
            this._item.dispose(param1);
            this._item = null;
            this._itemName.dispose(param1);
            this._itemName = null;
            this._numInput.dispose(param1);
            this._numInput = null;
            this._btnYes.dispose(param1);
            this._btnYes = null;
            this._btnNo.dispose(param1);
            this._btnNo = null;
            super.disposeImpl(param1);
            return;
        }// end function

        public function onMouseClick(event:MouseEvent) : void
        {
            var _loc_2:SPlayerItem = null;
            var _loc_3:Object = null;
            switch(event.target)
            {
                case this._btnYes:
                {
                    _loc_2 = new SPlayerItem();
                    _loc_2.uid = this._data.serverData.uid;
                    _loc_2.itemCode = this._data.serverData.itemCode;
                    _loc_2.itemAmount = this._numInput.value;
                    _loc_3 = {};
                    _loc_3.oper = new EGuildWarehouseOper(EGuildWarehouseOper._EGuildWarehouseIn);
                    _loc_3.item = [_loc_2];
                    _loc_3.oprMoney = null;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.Guild_wareHouse_oper, _loc_3));
                    this.hide();
                    break;
                }
                case this._btnNo:
                {
                    this.hide();
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function update() : void
        {
            if (this._data && this._uiCreateCom)
            {
                this._item.itemData = this._data;
                this._item.setAmountLabel("");
                this._itemName.htmlText = ItemsUtil.getItemName(this._data);
                this._numInput.minimum = 1;
                this._numInput.maximum = this._data.itemAmount;
                this._numInput.value = this._data.itemAmount;
                this._numInput.visible = this._data.itemInfo.overlay > 1;
            }
            return;
        }// end function

        private function onUpdateNumInput(event:Event) : void
        {
            return;
        }// end function

        public function showPanel(param1:ItemData, param2:int = 0, param3:int = 0) : void
        {
            this._data = param1;
            this.show(param2, param3);
            this.update();
            return;
        }// end function

        override public function hide() : void
        {
            this._data = null;
            super.hide();
            return;
        }// end function

        public static function get instance() : GuildNewDonateItemPanel
        {
            if (_instance == null)
            {
                _instance = new GuildNewDonateItemPanel;
            }
            return _instance;
        }// end function

    }
}
